#include <iostream>
#include <cstring>
#include <unordered_map>
#include <queue>
using namespace std;
const int N = 10;
unordered_map<string , int>dist;
string a , b;
string x[N] , y[N];
int cnt;

int bfs()
{  
    if(a == b) return 0;
    queue<string>q;
    q.push(a);
    dist[a] = 0;
    while(q.size())
    {
        string t = q.front(); q.pop();

        if(t == b) return dist[t];
        if(dist[t] >= 10) continue;

        for(int i = 0;i < cnt;i ++)
        {
            int pos = 0;
            while(t.find(x[i] , pos) != -1)
            {
                pos = (t.find(x[i] , pos));
                string tmp = t.substr(0 , pos) + y[i] + t.substr(pos + x[i].size());
                pos++;
                if(dist.count(tmp)) continue;
                dist[tmp] = dist[t] + 1;
                q.push(tmp);
            }
        }
    }
    return -1;
}

int main()
{
    cin >> a >> b;
    while(cin >> x[cnt] >> y[cnt]) cnt++;
    int ret = bfs();
    if(ret != -1) cout << ret << endl;
    else cout << "NO ANSWER!" << endl;

    return 0;
}